package sample.templates;

import java.util.Enumeration;
import java.util.Vector;

abstract class Trash {
	private double weight;

	Trash(double wt) {
		weight = wt;
	}

	abstract double value();

	double weight() {
		return weight;
	}

	public static void sumValue(Vector bin) {
		Enumeration e = bin.elements();
		double val = 0.0f;
		while (e.hasMoreElements()) {
			Trash t = (Trash) e.nextElement();

			val += t.weight * t.value();
			System.out.println("weight of" + t.getClass().getName() + "="
					+ t.weight());

		}
	}

}

class Aluminum extends Trash {
	static double val=1.67f;
	Aluminum(double wt) {
		super(wt);
	}

	@Override
	double value() {
		return val;
	}
	
	static void value(double newval){
		val=newval;
	}

}

class Paper extends Trash {

	static double val=0.10f;
	Paper(double wt) {
		super(wt);
	}

	@Override
	double value() {
		return val;
	}
	
	static void value(double newval){
		val=newval;
	}

}

class Glass extends Trash {

	static double val=0.23f;
	Glass(double wt) {
		super(wt);
	}

	@Override
	double value() {
		return val;
	}
	
	static void value(double newval){
		val=newval;
	}
}

public class RecycleA {
	public static void main(String[] args) {
		Vector bin = new Vector();
		for (int i = 0; i < 300; i++)
			switch ((int) (Math.random() *100)% 3) {//Math.random() in [0,1]
			case 0:
				bin.addElement(new Aluminum(Math.random() * 100));
				break;
			case 1:
				bin.add(new Paper(Math.random() * 100));
				break;
			case 2:
				bin.addElement(new Glass(Math.random() * 100));
			}

		Vector glassBin = new Vector(), paperBin = new Vector(), alBin = new Vector();

		Enumeration sorter = bin.elements();
		while (sorter.hasMoreElements()) {
			Object t = sorter.nextElement();
			if (t instanceof Aluminum) {
				alBin.addElement(t);
			}

			if (t instanceof Paper) {
				paperBin.addElement(t);
			}

			if (t instanceof Glass) {
				glassBin.addElement(t);
			}
		}

		Trash.sumValue(alBin);
		Trash.sumValue(paperBin);
		Trash.sumValue(glassBin);
		Trash.sumValue(bin);
	}

}
